class Websitearticles3Controller < ApplicationController
before_filter :authorize
    layout "websitearticles1"



      active_scaffold :article do |config|
  config.label = "Articles Report"

 
  
   config.actions.exclude :create,:update,:delete,:show

    config.columns[:category].label = 'Category 1' 	
    config.columns[:categoryt].label = 'Category 2'     	    
     config.columns[:user_published_by].label = 'Alias'  
    config.columns[:published].label = 'P'       
    config.columns[:published].form_ui = :checkbox    
#    config.columns[:published].inplace_edit = true
	  config.columns = [:title,:synopsis,:body,:category,:categoryt,:tag,:created_at,:created_by,:published,:published_at,:imageurl,:original_link,:last_accessed_at,:last_accessed_user,:last_updated_at,:last_updated_user,:user_published_by]
    config.list.columns.exclude :synopsis,:body,:imageurl,:original_link,:created_at,:created_by,:published_at	
    
		config.action_links.add 'mytest1', :label => 'Show Detail', :type => :record, :page => true    


#    config.show.columns.exclude(:title,:category,:categoryt,:tag,:created_at,:created_by,:published,:published_at,:last_accessed_at,:last_accessed_user,:last_updated_at,:last_updated_user,:user_published_by)       	
#  config.show.label = "Show Detail"
  


  end
  
    def mytest1
    redirect_to :controller=>'articles1',:action=>'show',:id=>params[:id]
  end
  


  def query_cond 
    @websit=Websitesinf.find(params[:id])
    @myteststr = "Articles Report For Website "+@websit.name
    redirect_to :controller=>'websitearticles3',:action=>'index',:id=>params[:id],:varaaa=>@myteststr,:searchcond=>{:from=>params[:from_created_at],:to=>params[:to_created_at],:aliasn=>params[:aliasn],:categoryn=>params[:categoryn],:categorytn=>params[:categorytn],:tagn=>params[:tagn]} 
  end


  
  def conditions_for_collection
   @lsearchstr = ""
   if params[:searchcond]
    @lsearchstr = "articles.websitesinf_id = "+params[:id]   
     if params[:searchcond][:aliasn]
     	@saliasn = params[:searchcond][:aliasn]
     	@lsearchstr = @lsearchstr + " and articles.user_published_by like '%%"+@saliasn+"%%'"
     else
      @lsearchstr = @lsearchstr + " and articles.user_published_by like '%%%%'"
     end 
     
     if params[:searchcond][:categoryn]
     	@scategoryn = params[:searchcond][:categoryn]
     	@lsearchstr = @lsearchstr + " and articles.category_id = "+@scategoryn
     else
     	@lsearchstr = @lsearchstr
     end     
     
     if params[:searchcond][:categorytn]
     	@scategorytn = params[:searchcond][:categorytn]
     	@lsearchstr = @lsearchstr + " and articles.categoryt_id = "+@scategorytn     	
     else
      @lsearchstr = @lsearchstr
     end 
     
     if params[:searchcond][:tagn]
     	@stagn = params[:searchcond][:tagn]
     	@lsearchstr = @lsearchstr + " and articles.tag_id = "+@stagn       	
     else
      @lsearchstr = @lsearchstr
     end  
     
     if params[:searchcond][:from]
     	@sfrom = params[:searchcond][:from]
     	@lsearchstr = @lsearchstr + " and articles.created_at >= '"+@sfrom+"'"             	
     else
      @lsearchstr = @lsearchstr
     end  
     
     if params[:searchcond][:to]
     	@sto = params[:searchcond][:to]
     	@lsearchstr = @lsearchstr + " and articles.created_at <= '"+@sto+"'"       	
     else
      @lsearchstr = @lsearchstr
     end          
     p @lsearchstr
    
     [@lsearchstr]    
#   		['articles.websitesinf_id = ? and create_at >= ? and created_at <= ? and user_published_by like %?% and category_id = ? and categoryt_id = ? and tag_id = ?',params[:websiteid],params[:searchcond][:from],params[:searchcond][:to],@saliasn,params[:searchcond][:categoryn],params[:searchcond][:categorytn],params[:searchcond][:tagn] ]
   else
	   ['articles.websitesinf_id = ?',params[:id] ]
	 end
  end

end
